import Zeroconf from 'react-native-zeroconf';
import {Device} from '../types';
export function searchDeviceInLAN(cb: (device: Device) => void) {
  const zeroconf = new Zeroconf();
  zeroconf.on('resolved', service => {
    if (service.name.includes('_electronic_album')) {
      console.log('发现 Electron 设备:', {
        name: service.name,
        ip: service.addresses[0],
      });
      cb({name: service.name, ip: service.addresses[0]});
    }
  });
  zeroconf.scan('_electron', 'tcp', 'local');
  setTimeout(() => {
    zeroconf.stop();
  }, 6000);
}
